import EventEmitter from "events";
export class SelectionModel extends EventEmitter {
  textModel_;
  selection_;
  constructor(textModel) {
    super();
    this.textModel_ = textModel;
    this.selection_ = { anchor: 0, focus: 0 };
  }
  getSelection() {
    return { ...this.selection_ };
  }
  setSelection(selection) {
    if (
      selection &&
      this.selection_ &&
      this.selection_.anchor == selection.anchor &&
      selection.focus === this.selection_.focus
    ) {
      return;
    }
    this.selection_ = selection ? { ...selection } : null;
  }
  // 是否是一个重叠
  isCollapsed() {
    return this.selection_ && this.selection_.anchor === this.selection_.focus;
  }
  // 是否反着选
  isBackward() {
    return this.selection_ && this.selection_.anchor > this.selection_.focus;
  }
}
export default SelectionModel;
